import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../config/app_bar_view.dart';
import '../generated/l10n.dart';
import 'home_tab_list_page.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  late TabController importTabController;
  List<String> tabList = [];
  double tabFontSize = 16.0;

  @override
  Widget build(BuildContext context) {
    return CommonAppWidget.navAppDrawBar(
      context: context,
      title: S.of(context).home,
      bgColor: Colors.white,
      childWidget: Column(
        children: [
          SizedBox(
            height: 40,
            child: TabBar(
              tabs: getTabList(),
              controller: importTabController,
              // labelColor: ThemeColor.black3D3D3DColor,
              // unselectedLabelColor: ThemeColor.grayA0A0A0Color,
              indicatorSize: TabBarIndicatorSize.label,
              // indicatorColor: ThemeColor.appColor,
              unselectedLabelStyle: TextStyle(
                fontSize: tabFontSize,
              ),
              // 未选择样式
              labelStyle: TextStyle(
                  fontSize: tabFontSize, fontWeight: FontWeight.w500), // 选择的样式
            ),
          ),
          Expanded(
            child: TabBarView(controller: importTabController, children: const [
              HomeTabListPage(
                type: HomeTabType.homeTabHotType,
              ),
              HomeTabListPage(
                type: HomeTabType.homeTabAllType,
              ),
            ]),
          ),
        ],
      ),
    );
  }

  //组装tab
  List<Widget> getTabList() {
    List<Widget> list =
        List.generate(tabList.length, (index) => Tab(text: tabList[index]));
    return list;
  }

  @override
  void initState() {
    super.initState();
    tabList = [S.of(Get.context!).hot, S.of(Get.context!).all];
    importTabController = TabController(length: tabList.length, vsync: this);
  }
  @override
  void dispose() {
   importTabController.dispose();
    super.dispose();
  }
}
